using System;
using System.Collections.Generic;
using System.Linq;
using Granite.Modeling;

namespace Rifts.Models.Definitions
{
	public class SkillDefinitionCollection : SimpleModelCollection<SkillDefinition> {

		public string Name
		{
			get { return Get<string>("Name"); }
			set { Set(value, "Name"); }
		}

		public SkillDefinition FindByName(string name)
		{
			return this.FirstOrDefault(s => s.Name == name);
		}

		public IList<SkillDefinition> FindAllByName(string skillName)
		{
			if (skillName.EndsWith("*", StringComparison.InvariantCultureIgnoreCase))
			{
				var nameStart = skillName.Substring(0, skillName.Length-1);
				return this.Where(s => s.Name.StartsWith(nameStart, StringComparison.InvariantCultureIgnoreCase)).ToList();
			}
			else
			{
				return this.Where(s => string.Equals(s.Name, skillName, StringComparison.InvariantCultureIgnoreCase)).ToList();
			}
		}
	}
}